<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="UTF-8" />
    <title>跨域方法之JSONP</title>
  </head>
  <body>
    <button>点击获取用户</button>
    <script>
      function callback(resp) {
        console.log(resp);
      }

      function request(url) {
        const script = document.createElement("script");
        script.src = url;
        script.onload = function () {
          script.remove();
        };
        document.body.appendChild(script);
      }

      document.querySelector("button").onclick = function () {
        request("http://localhost:8001/jsonp?callback=callback");
      };
    </script>
  </body>
</html>
